# -*- coding: utf-8 -*-
"""
Created on Thu Aug 01 11:13:40 2013

@author: Maxim
"""

from PBDO import *
from numpy import array,zeros


# --- problem 1 ---
def cost1(d,x,p):
    return 2.0*x[0] + 3.0*x[1]

def cnstr11(d,x,p):
    return -(20. - 3.*x[0] - 2.*x[1])

def cnstr12(d,x,p):
    return -(15.-2.*x[0] - 5.*x[1])

# --- problem 2 ---
def cost2(d,x,p):
    return -(x[0]+x[1]-10.)**2./30. - (x[0]-x[1]+10.)**2./120.

def cnstr21(d,x,p):
    return -(1.0 - x[0]*x[0]*x[1]/20.)

def cnstr22(d,x,p):
    val = 0.9063*x[0] + 0.4226*x[1] - 6.0
    return -(-1.0 + val**2.0 + val**3.0 - 0.6*val**4. - (-0.4226*x[0]+0.9063*x[1]))

def cnstr23(d,x,p):
    return -(1. - 80./(x[0]*x[0] + 8.*x[1]+5.))

# --- problem 3 ---
def cost3(d,x,p):
    pass

def cnstr31(d,x,p):
    pass


def test_problem_1():
    print 'test problem 1'
    alpha = 0.3
    tri = triangle()
    fuzzy = tri.getFuzzyNumber(0.,5.,10.)
    interval = fuzzy.getInterval(1.0-alpha)
    print interval
    params = parameters()
    params.addFuzzyVar(tri.getFuzzyNumber(interval[0],interval[1],interval[2]),0,10)
    params.addFuzzyVar(tri.getFuzzyNumber(interval[0],interval[1],interval[2]),0,10)
    opt = PBDO(cost1,(cnstr11,cnstr12),params)
    opt.solve()
    opt.display()

def test_problem_2():
    print '\ntest problem 2'
    alpha = 0.2
    tri = triangle()
    fuzzy = tri.getFuzzyNumber(0,5,10)
    interval = fuzzy.getInterval(1.0-alpha)
    print interval
    params = parameters()
    params.addFuzzyVar(tri.getFuzzyNumber(interval[0],interval[1],interval[2]),0,10)
    params.addFuzzyVar(tri.getFuzzyNumber(interval[0],interval[1],interval[2]),0,10)
    opt = PBDO(cost2,(cnstr21,cnstr22,cnstr23),params)
    opt.solve()
    opt.display()

if __name__=="__main__":
    test_problem_1()
    test_problem_2()